import 'package:flutter/material.dart';
import 'package:helloworld/res/depositData.dart';
import 'package:helloworld/tabs.dart';
import 'package:dio/dio.dart';
import 'dart:ui';
class AddDeposit extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _AddDeposit();
  }
}

class _AddDeposit extends State<AddDeposit>{
  var _count = TextEditingController();
  var _number = TextEditingController();
  var _deposit = TextEditingController();
  Brightness brightnessValue ;
  addDeposit()async{
    Response response = await Dio().post("http://123.207.114.127:1314/deposit/addDeposit",queryParameters: {
      'depositcount': _count.text,
      'depositnumber' : _number.text,
      'deposit': double.parse(_deposit.text),
    });
  }
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    brightnessValue = window.platformBrightness;
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text('添加存款'),
        actions: <Widget>[
          InkWell(
            child: Padding(
              child:Text('保存',style: TextStyle(color: Colors.white,fontSize: 20),),
              padding: EdgeInsets.all(16),
            ),
            onTap: (){
              addDeposit();
              Future.delayed(Duration(milliseconds: 50), (){
                Navigator.of(context).pop();
                Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (context) => new Tabs( index:1)), (route) =>route==null);
              });
            },
          )
        ],
      ),
      body: Padding(
        padding: EdgeInsets.all(20),
        child: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              TextField(
                keyboardAppearance: brightnessValue,
                autofocus: true,
                decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: '账户'
                ),
                onChanged: (value){
                  setState(() {
                    _count.text = value;
                  });
                },
              ),
              SizedBox(height: 10,),
              TextField(
                keyboardAppearance: brightnessValue,
                keyboardType: TextInputType.number,
                decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: '尾号'
                ),
                onChanged: (value){
                  setState(() {
                    _number.text = value;
                  });
                },
              ),
              SizedBox(height: 10,),
              TextField(
                keyboardAppearance: brightnessValue,
                keyboardType: TextInputType.numberWithOptions(decimal: true),
                decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: '金额'
                ),
                onChanged: (value){
                  setState(() {
                    _deposit.text = value;
                  });
                },
              )
            ],
          ),
          scrollDirection: Axis.vertical,
        ),
      ),
    );
  }
}